import axios from 'axios'

const instance = axios.create({
  baseURL: import.meta.env.VITE_APP_URL,
  timeout: 10000
})

instance.interceptors.request.use(
  (config) => {
    // console.log('请求拦截', config)
    if (localStorage.getItem('token')) {
      config.headers['Authorization'] =
        'Bearer ' + localStorage.getItem('token')
    }
    // config.headers['Authorization'] = 'Bearer ' + localStorage.getItem('token')
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

instance.interceptors.response.use(
  (response) => {
    // console.log('响应拦截', response)
    return response
  },
  (error) => {
    return Promise.reject(error)
  }
)

export default instance
